/*------------------------------------------------------------------------------
--                                                                            --
--       This software is confidential and proprietary and may be used        --
--        only as expressly authorized by a licensing agreement from          --
--                                                                            --
--                            Hantro Products Oy.                             --
--                                                                            --
--      In the event of publication, the following notice is applicable:      --
--                                                                            --
--                   (C) COPYRIGHT 2004 HANTRO PRODUCTS OY                    --
--                            ALL RIGHTS RESERVED                             --
--                                                                            --
--          The entire notice above must be reproduced on all copies.         --
--                                                                            --
--------------------------------------------------------------------------------
--
--  Abstract : Hantro Jpeg Encoder API
--
--------------------------------------------------------------------------------
--
--  Version control information, please leave untouched.
--
--  $RCSfile: jpegencapi.h,v $
--  $Revision: 1.4 $
--  $Date: 2004/12/20 13:38:06 $
--
------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------

    Table of contents

    1. Include headers
    2. Module defines
    3. Data types
    4. Function prototypes

------------------------------------------------------------------------------*/

#ifndef __JPEGENCAPI_H__
#define __JPEGENCAPI_H__

/*------------------------------------------------------------------------------
    1. Include headers
------------------------------------------------------------------------------*/

#include "basetype.h"

/*------------------------------------------------------------------------------
    2. Module defines
------------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C"
{
#endif

    typedef void *JpegEncInst;

    typedef enum
    {
        JPEGENC_FRAME_READY = 1,
        JPEGENC_RESTART_INTERVAL = 2,
        JPEGENC_OK = 0,
        JPEGENC_ERROR = -1,
        JPEGENC_NULL_ARGUMENT = -2,
        JPEGENC_INVALID_ARGUMENT = -3,
        JPEGENC_MEMORY_ERROR = -4,
        JPEGENC_INVALID_STATUS = -5,
        JPEGENC_OUTPUT_BUFFER_OVERFLOW = -6,
        JPEGENC_EWL_ERROR = -7,
        JPEGENC_EWL_MEMORY_ERROR = -8,
        JPEGENC_HW_ERROR = -9,
        JPEGENC_HW_TIMEOUT = -10,
        JPEGENC_INSTANCE_ERROR = -11
    }
    JpegEncRet;

    typedef enum
    {
        JPEGENC_YUV420 = 0,
        JPEGENC_GREYSCALE = 1
    }
    JpegEncFrameType;

    typedef enum
    {
        JPEGENC_WHOLE_FRAME = 0,
        JPEGENC_SLICED_FRAME = 1
    }
    JpegEncCodingType;

    enum JpegEncFrameHeaders
    {
        JPEGENC_REDUCED_MJPEG_HEADERS = 0,
        JPEGENC_FULL_JFIF_HEADERS = 1
    };

    typedef enum
    {
        JPEGENC_NO_UNITS = 0,
        JPEGENC_DOTS_PER_INCH = 1,
        JPEGENC_DOTS_PER_CM = 2
    }
    JpegEncAppUnitsType;

/*------------------------------------------------------------------------------
    3. Data types
------------------------------------------------------------------------------*/

/* Version information */
    typedef struct
    {
        i32 major;  /* Encoder API major version */
        i32 minor;  /* Encoder API minor version */
    }
    JpegEncApiVersion;

/* Encoder configuration */
    typedef struct
    {
        i32 inputWidth; /* Number of pixels/line in input image */
        i32 inputHeight;    /* Number of lines in input image */
        i32 xOffset;    /* Pixels from top-left corner of input image */
        i32 yOffset;    /*   to top-left corner of encoded image */
        i32 codingWidth;    /* Width of encoded image */
        i32 codingHeight;   /* Height of encoded image */
        i32 restartInterval;    /* Restart interval (MCU lines) */
        i32 qLevel; /* Quantization level (0 - 9) */
        JpegEncFrameType frameType; /* YUV 4:2:0 / greyscale */
        JpegEncCodingType codingType;   /* Whole frame or Sliced Mode */
        JpegEncAppUnitsType unitsType;  /* units for X and Y pixel densities */
        i32 Xdensity;   /* Horizontal pixel density */
        i32 Ydensity;   /* Vertical pixel density */
    }
    JpegEncCfg;

/* Input info */
    typedef struct
    {
        i32 frameHeader;    /* one of the JpegEncFrameHeaders values */
        u32 busLum; /* Bus address of luminance input   (Y) */
        u32 busCb;  /* Bus address of chrominance input (Cb) */
        u32 busCr;  /* Bus address of chrominance input (Cr) */
        u8 *pOutBuf;    /* Pointer to output buffer */
        u32 outBufBusAddress;   /* Bus address of the output buffer */
        i32 outBufSize; /* Size of output buffer (bytes) */
    }
    JpegEncIn;

/* Output info */
    typedef struct
    {
        i32 jfifSize;   /* Encoded JFIF size (bytes) */
    }
    JpegEncOut;

/*------------------------------------------------------------------------------
    4. Function prototypes
------------------------------------------------------------------------------*/

/* Version information */
    JpegEncApiVersion JpegEncGetVersion(void);

/* Initialization & release */
    JpegEncRet JpegEncInit(JpegEncCfg * pEncCfg, JpegEncInst * instAddr);
    JpegEncRet JpegEncRelease(JpegEncInst inst);

/* Jfif generation */
    JpegEncRet JpegEncEncode(JpegEncInst inst,
                             JpegEncIn * pEncIn, JpegEncOut * pEncOut);

#ifdef __cplusplus
}
#endif

#endif
